# -*- coding: utf-8 -*-
'''
Created on Apr 6, 2013

@author: LONG HOANG GIANG
'''

import sys, os
from urlparse import urljoin
sys.path.append(os.path.join(os.path.dirname(__file__), '../'))
import pyLib
import logging

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt='%d/%m/%Y %H:%M:%S')

def getDetail(url, name):
    tree = pyLib.loadWeb(url).build_tree()
    detailNode = tree.xpath("//div[contains(@id, 'id') and @style='display:none']")[0]
    content = pyLib.cleanHTML(pyLib.Etree.tostring(detailNode))
    print content
    

def process(url, minPage=1, maxPage=15):
    urlfm = url
    for page in range(minPage, maxPage + 1):
        logging.debug("process page {0}".format(page))
        url = urlfm + "&page={0}".format(page)
        tree = pyLib.loadWeb(url).build_tree()
        for node in tree.xpath("//td[@class='ucell'][1]/a"):
            name = pyLib.stringify(node)
            href = node.get('href', '')
            if href == '' or name == '': continue
            print name, href
        





if __name__ == '__main__':
    
#    process('http://lmvn.com/truyen/index.php?func=main&cat=29')
    getDetail('http://lmvn.com/truyen/index.php?func=viewpost&id=NmhSdgdFHw3pypqQEaFGV69PQATPO7d2', "AGIANG")
    logging.info("Finished")
    os._exit(1)